package com.hulk.dryad.manage.boot.analyzer;

import com.google.common.base.Throwables;
import net.dreamlu.mica.auto.annotation.AutoFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.boot.diagnostics.FailureAnalyzer;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.core.Ordered;

/**
 * 启动阶段的异常分析，方便排查问题
 *
 * @author hulk
 */
@AutoFailureAnalyzer
public class DryadFailureAnalyzer implements FailureAnalyzer, Ordered {

	@Override
	public FailureAnalysis analyze(Throwable failure) {
		String failureMessage = failure.getMessage();
		Throwable throwable = NestedExceptionUtils.getMostSpecificCause(failure);
		String description = failureMessage + "\n\n" + Throwables.getStackTraceAsString(throwable);
		return new FailureAnalysis(description, null, throwable);
	}

	@Override
	public int getOrder() {
		return Ordered.LOWEST_PRECEDENCE;
	}
}
